package com.igeek.shop.web.gouwuche;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.igeek.shop.entity.PageBean;
import com.igeek.shop.entity.Product;
import com.igeek.shop.service.ProductService;

public class ProductListByCidServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		//根据商品的分类查找该分类下的所有商品（默认找第一页的内容）
		String cid = req.getParameter("cid");
		
		String page = req.getParameter("currentPage");
		
		int currentPage = 1;
		if(page!=null){
			currentPage  = Integer.parseInt(page);
		}
		
		int currentCount =  12;
		
		//
		ProductService service = new ProductService();
		PageBean<Product> pageBean = service.findProductListByCid(cid,currentPage,currentCount);
		req.setAttribute("pageBean", pageBean);
		req.setAttribute("cid", cid);
		
		//页面的跳转
		req.getRequestDispatcher("/product_list.jsp").forward(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(req,resp);
	}

	
}
